
class Dashboard::DesignCasesController < Dashboard::BaseController

  before_action :require_logined

  def index
    @design_cases = current_user.design_cases
  end

  def new
    @design_case = DesignCase.find(params[:id]) if params[:id]
  end

  def create
    if params[:case_id].present?
      @design_case = DesignCase.find params[:case_id]
      @design_case.update params[:design_case].permit!
    else
      params[:design_case][:user_id] = current_user.id
      @design_case = DesignCase.new(params[:design_case].permit!)
    end
    if @design_case.save
      redirect_to new_dashboard_design_case_path(id: @design_case.id)
    else
      render action: :new
    end
  end

  def destroy
    @design_case = DesignCase.find params[:id]

    if @design_case.destroy
      flash[:notice] = "删除成功"
      redirect_to dashboard_design_cases_path
    else
      flash[:notice] = "删除失败"
      redirect_to :back
    end
  end

end
